<?php

namespace app\api\controller;

use app\common\lib\QrcodeServer;
use think\Controller;
use think\facade\App;

class Common extends Auth
{

    public function logout()
    {
        $update = [
            'where' => [
                'table' => $this->table,
                'status' => 1,
                'userid' => $this->userid,
            ],
            'data' => ['status' => 0],
        ];

        $ans = $this->updateTable('user_login', $update);

        if ($ans) {
            return $this->json([], 1000, '注销成功');
        } else {
            return $this->json([], 2000, '注销失败');
        }
    }

    public function getRecommendedCode()
    {
        $where = ['table' => $this->table, 'userid' => $this->userid];
        $info = $this->findTable('recommended_code', ['where' => $where]);

        if (empty($info)) {
            $code = getrange();
            $info = $this->findTable('recommended_code', ['where' => ['code' => $code], 'field' => 'id']);
            if (!empty($info)) {
                $code = getrange();
            }
            $qrimg = $this->createQrcode($code);
            $data = [
                'table' => $this->table,
                'userid' => $this->userid,
                'code' => $code,
                'qrcodeimg' => $qrimg,
            ];

            $ans = $this->insertTable('recommended_code', $data);
        } else if (empty($qrcodeimg)) {
            $qrimg = $this->createQrcode($info['code']);

            $update = [
                'where' => ['id' => $info['id']],
                'data' => ['qrcodeimg' => $qrimg],
            ];

            $ans = $this->updateTable('recommended_code', $update);
        }

        if ($ans) {
            $info = $this->findTable('recommended_code', ['where' => $where]);
            return $this->json($info, 1000);
        } else {
            return $this->json([], 2000, '获取失败');
        }
    }


    public function addRecommendedLog()
    {
        $code = input('post.code');

        if (empty($code)) {
            return $this->json([], 2000, '请填写邀请码');
        }

        $where = ['promotetotable' => $this->table, 'promotetouserid' => $this->userid];
        $info = $this->findTable('recommended_log', ['where' => $where]);

        if (!empty($info)) {
            return $this->json([], 2000, '你已被其他邀请人员绑定了');
        }

        $res = $this->findTable('recommended_code', ['where' => ['code' => $code], 'field' => 'id,table,userid']);

        if (empty($res) || ($res['table'] == $this->table && $res['userid'] && $this->userid)) {
            return $this->json([], 2000, '请输入正确的邀请码');
        }

        $data = [
            'promotetable' => $res['table'],
            'promoteuserid' => $res['userid'],
            'promotetotable' => $this->table,
            'promotetouserid' => $this->userid,
            'code' => $code,
        ];
        \think\facade\Db::startTrans();
        if ($this->table == 'coach') {
            if ($res['table'] == 'coach') {
                $result = $this->findTable('coach', ['where' => ['coachid' => $res['userid']], 'field' => 'level_id']);
                if (empty($result)) {
                    $level_id = 2;
                } else {
                    $level_id = (int) $result['level_id'] + 1;
                }
                $agent_id = $res['userid'];
            } else {
                $level_id = 2;
                $agent_id = 0;
            }

            $where = ['coachid' => $this->userid];
            $update = [
                'where' => $where,
                'data' => [
                    'level_id' => $level_id,
                    'agent_id' => $agent_id,
                ],
            ];
            $row = $this->updateTable('coach', $update);
        } else {
            $row = 1;
        }

        $ans = $this->insertTable('recommended_log', $data);

        if ($res['table'] == 'coach') {
            $this->addCustomer(['memberid' => $info['memberid'], 'coachid' => $this->userid, 'source' => 2]);
        }
   
        if ($ans && $row) {
            \think\facade\Db::commit();
            return $this->json([], 1000, '提交成功');
        } else {
            \think\facade\Db::rollback();
            return $this->json([], 2000, '提交失败');
        }
    }


    public function getRecommendedLogList()
    {
        $get = input('get.');

        $data = $where = [];
        if (!empty($get['begin']) && !empty($get['end'])) {
            $begin = strtotime($get['begin']);
            $end = strtotime(date('Y-m-d', strtotime('+1 day', $get['end'])));
            $where[] = ['addtime', 'between', [$begin, $end]];
        }

        $where[] = ['promotetable', '=', $this->table];
        $where[] = ['promoteuserid', '=', $this->userid];
        $where[] = ['isdel', '=', 0];
        $data['where'] = $where;
        $data['tableName'] = 'recommended_log';
        $data['totalCount'] = $this->countTable('recommended_log', $data);
        $data = $this->buildCount($data);
        $data['order'] = 'addtime desc';
        $list = $this->listTable('recommended_log', $data);

        if ($this->table == 'member') {
            $user = $this->listTable('member', [
                'where' => [
                    'memberid' => array_column($list, 'memberid')
                ],
                'field' => 'memberavatar as avatar,membertruename as truename,memberbirthday as birthday,memberid as id,membersex as sex'
            ]);
        } else if ($this->table == 'coach') {
            $user = $this->listTable('coach', [
                'where' => [
                    'coachid' => array_column($list, 'coachid')
                ],
                'field' => 'coachavatar as avatar,coachtruename as truename,coachbirthday as birthday,coachsex as sex,coachid as id'
            ]);
        }

        foreach ($list as $key => $val) {
            $list[$key]['addtime'] = empty($val['addtime']) ? '' : date('Y-m-d H:i:s', $val['addtime']);
            if (!empty($user)) {
                foreach ($user as $cv) {
                    if ($cv['id'] == $val['promoteuserid']) {
                        $list[$key]['truename'] = $cv['truename'];
                        $list[$key]['avatar'] = $cv['avatar'];
                        $list[$key]['sex'] = $cv['sex'];
                        $list[$key]['age'] = empty($cv['birthday']) ? '暂无' : birthday($cv['birthday']);
                    }
                }
            }
        }
        $data['list'] = $list;
        return $this->json($data, 1000);
    }

    /**
     * 直接输出二维码 + 生成二维码图片文件
     */
    public function createQrcode($content = 'test')
    {
        // 自定义二维码配置
        $config = [
            'title' => true,
            'title_content' => $content,
            'logo_size' => 80,
        ];

        // 写入文件
        $qr_url = '';
        $file_name = './static/uploads/qrcode/' . $this->table . '/' . $this->userid . '/'; // 定义保存目录

        $config['file_name'] = $file_name;
        $config['generate'] = 'writefile';

        $qr_code = new QrcodeServer($config);
        $res = $qr_code->createServer($qr_url);
        if ($res['success'] && !empty($res['data']['url'])) {
            return $res['data']['url'];
        } else {
            return false;
        }
    }

    public function getNoticeList()
    {
        $get = input('get.');

        $data = $where = [];
        if (!empty($get['begin']) && !empty($get['end'])) {
            $begin = strtotime($get['begin']);
            $end = strtotime(date('Y-m-d', strtotime('+1 day', $get['end'])));
            $where[] = ['addtime', 'between', [$begin, $end]];
        }

        if (!empty($get['type']) && in_array($get['type'], [1, 2, 3])) {
            $where[] = ['type', '=', $get['type']];
        }

        $reciveutype = $this->table == 'coach' ? 2 : 3;
        $where[] = ['status', '>', 0];
        $where[] = \think\facade\Db::raw("reciveutype in (1,{$reciveutype}) or (reciveuid={$this->userid} and reciveutable='{$this->table}')");
        $data['where'] = $where;
        $data['tableName'] = 'notice';
        $data['totalCount'] = $this->countTable('notice', $data);
        $data = $this->buildCount($data);
        $list = $this->listTable('notice', $data);

        foreach ($list as $key => $val) {
            $list[$key]['addtime'] = empty($val['addtime']) ? '' : date('Y-m-d H:i:s', $val['addtime']);
            $list[$key]['updatetime'] = empty($val['updatetime']) ? '' : date('Y-m-d H:i:s', $val['updatetime']);
            $list[$key]['img'] = empty($val['img']) ? [] : explode(',', $val['img']);
        }
        $data['list'] = $list;
        return $this->json($data, 1000);
    }

    public function getNoticeDetail()
    {
        $get = input('get.');

        if (empty($get['msgid'])) {
            return $this->json([], 2000, '请求参数错误');
        }

        $reciveutype = $this->table == 'coach' ? 2 : 3;
        $where = [
            ['msgid', '=', $get['msgid']],
            \think\facade\Db::raw("reciveutype in (1,{$reciveutype}) or (reciveuid={$this->userid} and reciveutable='{$this->table}')"),
        ];
        $info = $this->findTable('notice', ['where' => $where, 'order' => 'msgid desc']);
        if (!empty($info)) {
            $info['addtime'] = empty($info['addtime']) ? '' : date('Y-m-d H:i:s', $info['addtime']);
            $info['updatetime'] = empty($info['updatetime']) ? '' : date('Y-m-d H:i:s', $info['updatetime']);
            $info['img'] = empty($info['img']) ? [] : explode(',', $info['img']);
        }

        return $this->json($info, 1000);
    }


    public function getEvaluateList()
    {
        $get = input('get.');

        $data = $where = [];
        if (!empty($get['begin']) && !empty($get['end'])) {
            $begin = strtotime($get['begin']);
            $end = strtotime(date('Y-m-d', strtotime('+1 day', $get['end'])));
            $where[] = ['addtime', 'between', [$begin, $end]];
        }

        // 好评1 中评2 差评3
        if (!empty($get['scoretype']) && in_array($get['scoretype'], [1, 2, 3])) {
            $scoretype = [1 => [5, 4], 2 => [3], [2, 1]];
            $where[] = ['score', 'in', $scoretype[$get['scoretype']]];
        }

        if ($this->table == 'coach') {
            $where[] = ['coachid', '=', $this->userid];
        } else {
            $where[] = ['memberid', '=', $this->userid];
        }

        $where[] = ['status', '=', 1];
        $where[] = ['isdel', '=', 0];
        $data['where'] = $where;
        $data['tableName'] = 'evaluate';
        $data['totalCount'] = $this->countTable('evaluate', $data);
        $data = $this->buildCount($data);
        $data['order'] = 'addtime desc';
        $list = $this->listTable('evaluate', $data);

        $member = $this->listTable('member', [
            'where' => [
                'memberid' => array_column($list, 'memberid')
            ],
            'field' => 'memberavatar,membertruename,memberbirthday,memberid,membersex,memberid,memberage'
        ]);

        $coach = $this->listTable('coach', [
            'where' => [
                'coachid' => array_column($list, 'coachid')
            ],
            'field' => 'coachavatar,coachtruename,coachbirthday,coachid,coachsex,coachage'
        ]);

        $order = $this->listTable('order', [
            'where' => [
                'orderid' => array_column($list, 'orderid')
            ],
            'field' => 'ordername,ordersn,orderid'
        ]);

        foreach ($list as $key => $val) {
            $list[$key]['addtime'] = empty($val['addtime']) ? '' : date('Y-m-d H:i:s', $val['addtime']);
            $list[$key]['updatetime'] = empty($val['updatetime']) ? '' : date('Y-m-d H:i:s', $val['updatetime']);
            $list[$key]['imgs'] = empty($val['imgs']) ? [] : explode(',', $val['imgs']);
            foreach ($member as $v) {
                if ($v['memberid'] == $val['memberid']) {
                    $list[$key]['membertruename'] = $v['membertruename'];
                    $list[$key]['memberavatar'] = $v['memberavatar'];
                    $list[$key]['membersex'] = $v['membersex'];
                    $list[$key]['memberage'] = empty($v['memberbirthday']) ? (empty($v['memberage']) ? '暂无' : $v['memberage']) : birthday($v['memberbirthday']);
                }
            }
            foreach ($coach as $cv) {
                if ($cv['coachid'] == $val['coachid']) {
                    $list[$key]['coachtruename'] = $cv['coachtruename'];
                    $list[$key]['coachavatar'] = $cv['coachavatar'];
                    $list[$key]['coachex'] = $cv['coachsex'];
                    $list[$key]['coachage'] = empty($cv['coachbirthday']) ? (empty($cv['coachage']) ? '暂无' : $cv['coachage']) : birthday($cv['coachbirthday']);
                }
            }
            foreach ($order as $ov) {
                if ($ov['orderid'] == $val['orderid']) {
                    $list[$key]['ordername'] = $ov['ordername'];
                    $list[$key]['ordersn'] = $ov['ordersn'];
                }
            }
        }
        $data['list'] = $list;
        return $this->json($data, 1000);
    }


    public function getEvaluateDetail()
    {
        $get = input('get.');

        if (empty($get['evaluateid'])) {
            return $this->json([], 2000, '请求参数错误');
        }

        $where = ['evaluate.evaluateid' => $get['evaluateid'], 'evaluate.status' => 1, 'evaluate.isdel' => 0];
        $info = $this->findTable('evaluate', [
            'where' => $where,
            'join' => [
                ['member member', 'member.memberid = evaluate.memberid'],
                ['coach coach', 'coach.coachid = evaluate.coachid'],
                ['order order', 'order.orderid = evaluate.orderid'],
            ],
            'field' => 'evaluate.*,member.memberavatar,member.membertruename,member.memberbirthday,member.memberid,member.membersex,order.ordername,order.ordersn,coach.coachavatar,coach.coachtruename,coach.coachbirthday,coach.coachid,coach.coachsex,coach.coachid',
            'order' => 'evaluateid desc'
        ]);

        $info['imgs'] = empty($info['imgs']) ? [] : explode(',', $info['imgs']);
        return $this->json($info, 1000);
    }

    public function getOrderDetail()
    {
        $get = input('get.');

        if (empty($get['orderid'])) {
            return $this->json([], 2000, '请求参数错误');
        }

        if (!empty($get['longitude']) && !empty($get['latitude'])) {
            $longitude = $get['longitude'];
            $latitude = $get['latitude'];
        }

        $where = ['order.orderid' => $get['orderid'], 'order.isdel' => 0];

        $field = "order.*,member.memberavatar,member.membertruename,member.memberbirthday,member.membersex,coach.coachavatar,coach.coachtruename,coach.coachbirthday,coach.coachid,coach.coachsex";

        $info = $this->findTable('order', [
            'where' => $where,
            'join' => [
                ['member member', 'member.memberid = order.memberid'],
                ['coach coach', 'coach.coachid = order.coachid', 'left'],
            ],
            'field' => $field,
            'order' => 'orderid desc'
        ]);

        if (!empty($longitude) && !empty($latitude) && !empty($info['longitude']) && !empty($info['latitude'])) {
            /*需要传入经纬度，默认正序*/
            $info['distance'] = distance($latitude, $longitude, $info['latitude'], $info['longitude']);
        }

        $applyCount = $this->countTable('apply_order', ['where' => [
            'orderid' => $info['orderid']
        ]]);

        $info['applycount'] = $applyCount;

        if ($this->table == 'coach') {
            $info['isapply'] = 0;
            if (empty($apply)) {
                $where = [
                    'coachid' => $this->userid,
                    'orderid' => $info['orderid'],
                ];
                $apply = $this->findTable('apply_order', ['where' => $where]);
                if (!empty($apply)) {
                    $apply = 1;
                }
            }
            $info['isapply'] = $apply;
        }

        return $this->json($info, 1000);
    }

    public function getRewardList()
    {
        $get = input('get.');

        $data = $where = [];
        if (!empty($get['begin']) && !empty($get['end'])) {
            $begin = strtotime($get['begin']);
            $end = strtotime(date('Y-m-d', strtotime('+1 day', $get['end'])));
            $where[] = ['addtime', 'between', [$begin, $end]];
        }

        if ($this->table == 'coach') {
            $where[] = ['coachid', '=', $this->userid];
        } else {
            $where[] = ['memberid', '=', $this->userid];
        }

        $where[] = ['isdel', '=', 0];
        $data['where'] = $where;
        $data['tableName'] = 'reward';
        $data['totalCount'] = $this->countTable('reward', $data);
        $data = $this->buildCount($data);
        $data['order'] = 'addtime desc';
        $list = $this->listTable('reward', $data);

        $member = $this->listTable('member', [
            'where' => [
                'memberid' => array_column($list, 'memberid')
            ],
            'field' => 'memberavatar,membertruename,memberbirthday,memberid,membersex,memberage'
        ]);

        $order = $this->listTable('order', [
            'where' => [
                'orderid' => array_column($list, 'orderid')
            ],
            'field' => 'ordername,ordersn,orderid'
        ]);

        $coach = $this->listTable('coach', [
            'where' => [
                'coachid' => array_column($list, 'coachid')
            ],
            'field' => 'coachavatar,coachtruename,coachbirthday,coachid,coachsex,coachage'
        ]);

        foreach ($list as $key => $val) {
            $list[$key]['addtime'] = empty($val['addtime']) ? '' : date('Y-m-d H:i:s', $val['addtime']);
            $list[$key]['paynotifytime'] = empty($val['paynotifytime']) ? '' : date('Y-m-d H:i:s', $val['paynotifytime']);
            foreach ($member as $v) {
                if ($v['memberid'] == $val['memberid']) {
                    $list[$key]['membertruename'] = $v['membertruename'];
                    $list[$key]['memberavatar'] = $v['memberavatar'];
                    $list[$key]['membersex'] = $v['membersex'];
                    $list[$key]['age'] = empty($v['memberbirthday']) ? (empty($v['memberage']) ? '暂无' : $v['memberage']) : birthday($v['memberbirthday']);
                }
            }
            foreach ($coach as $cv) {
                if ($cv['coachid'] == $val['coachid']) {
                    $list[$key]['coachtruename'] = $cv['coachtruename'];
                    $list[$key]['coachavatar'] = $cv['coachavatar'];
                    $list[$key]['coachex'] = $cv['coachsex'];
                    $list[$key]['coachage'] = empty($cv['coachbirthday']) ? (empty($cv['coachage']) ? '暂无' : $cv['coachage']) : birthday($cv['coachbirthday']);
                }
            }
            foreach ($order as $ov) {
                if ($ov['orderid'] == $val['orderid']) {
                    $list[$key]['ordername'] = $ov['ordername'];
                    $list[$key]['ordersn'] = $ov['ordersn'];
                }
            }
        }
        $data['list'] = $list;
        return $this->json($data, 1000);
    }

    public function addFeedback()
    {
        $post = input('post.');

        if (empty($post['title'])) {
            return $this->json([], 2000, '请填写标题');
        }

        if (empty($post['content'])) {
            return $this->json([], 2000, '请填写内容');
        }

        $data = [
            'title' => $post['title'],
            'content' => $post['content'],
            'table' => $this->table,
            'userid' => $this->userid,
            'img' => empty($post['img']) ? '' : (is_array($post['img']) ? $post['img'] : implode(',', $post['img'])),
            'mobile' => empty($post['mobile']) ? '' : $post['mobile'],
        ];

        $ans = $this->insertTable('feedback', $data);

        if ($ans) {
            return $this->json([], 1000, '提交成功');
        } else {
            return $this->json([], 2000, '提交失败');
        }
    }

    /**
     * 
     */
    public function getUserInfo()
    {
        $data = $this->user;
        return $this->json($data, 1000);
    }


    /**
     * 获取聊天短语
     */
    public function getPhrase()
    {
        $where = [
            ['isdel', '=', 0],
            ['status', '=', 1],
            ['table', 'in', ['all', $this->table]],
        ];
        $info = $this->listTable('phrase', ['where' => $where, 'order' => 'id desc', 'nolimit' => 1]);

        return $this->json($info, 1000);
    }


    public function getOrderRecommend()
    {
        $get = input('get.');
        if (empty($get['orderid'])) {
            return $this->json([], 2000, '请求参数错误');
        }

        $info = $this->findTable('order', ['where' => [
            ['isdel', '=', 0],
            ['status', '=', $get['orderid']]
        ]]);

        if (empty($info)) {
            return $this->json([], 1000);
        }

        if (!empty($info['longitude']) && !empty($info['latitude'])) {
            $longitude = $info['longitude'];
            $latitude = $info['latitude'];
        } else {
            $address = $info['collegeaddress'] . $info['collegedetailedaddress'];
            $result = $this->getgaode($address);
            if ($result['code'] == 1000) {
                if (!empty($result['data'])) {
                    $location = $result['data'];
                    $longitude = empty($location[0]) ? '' : $location[0];
                    $latitude = empty($location[1]) ? '' : $location[1];
                }
            } else {
                return $this->json($result['data'], $result['code'], $result['msg']);
            }
        }

        $where[] = ['isdel', '=', 0];
        $where[] = ['status', '=', 3];
        $data['where'] = $where;
        $tableName = 'coach';

        /*距离排序*/
        if (!empty($longitude) && !empty($latitude)) {
            /*需要传入经纬度，默认正序*/
            $data['field'] = "*, (st_distance(point (longitude,latitude), point (" . htmlspecialchars($longitude) . "," . htmlspecialchars($latitude) . "))*111195/1000 ) as distance";
            $data['order'] = 'distance asc';
        }

        $data['totalCount'] = $this->countTable($tableName, $data);
        $data = $this->buildCount($data);
        $list = $this->listTable($tableName, $data);

        $where = [
            ['coachid', 'in', array_column($list, 'coachid')],
            ['orderid', '=', $info['orderid']],
        ];
        $invitation = $this->listTable('invitation', ['where' => $where, 'field' => 'coachid']);

        foreach ($list as $key => $val) {
            $list[$key]['isinvitation'] = 1;
            foreach ($invitation as $k => $v) {
                if ($v['coachid'] == $val['coachid']) {
                    $list[$key]['isinvitation'] = 0;
                }
            }
        }

        $data['list'] = $list;
        return $this->json($data, 1000);
    }

    public function getMemberWyyx()
    {
        $get = input('get.');
        if (empty($get['memberid'])) {
            return $this->json([], 2000, '请求参数错误');
        }

        $info = $this->findTable('member', ['where' => [
            ['isdel', '=', 0],
            ['memberid', '=', $get['memberid']]
        ]]);

        if (empty($info)) {
            return $this->json([], 2000, '用户不存在');
        }

        if (empty($info['yxaccid']) || empty($info['yxtoken'])) {
            $yx = new \app\common\lib\YxUtils();
            $res = $yx->createUserId('member_' . $get['memberid'], $info['membertruename']);
            if ($res['code'] == 200) {
                $yxaccid = empty($res['info']['accid']) ? '' : $res['info']['accid'];
                $yxtoken = empty($res['info']['token']) ? '' : $res['info']['token'];
            } else {
                $res = $yx->updateUserToken('member_' . $get['memberid']);
                if ($res['code'] == 200) {
                    $yxaccid = empty($res['info']['accid']) ? '' : $res['info']['accid'];
                    $yxtoken = empty($res['info']['token']) ? '' : $res['info']['token'];
                } else {
                    return $this->json([], 2000, empty($res['desc']) ? json_encode($res) : $res['desc']);
                }
            }

            $where = ['memberid' => $info['memberid']];
            $update = [
                'where' => $where,
                'data' => [
                    'yxaccid' => $yxaccid,
                    'yxtoken' => $yxtoken
                ],
            ];
            $this->updateTable('member', $update);
        } else {
            $yxaccid = $info['yxaccid'];
            $yxtoken = $info['yxtoken'];
        }

        $data = ['yxaccid' => $yxaccid];
        if ($this->userid == $get['memberid'] && $this->table == 'member') {
            $data['yxtoken'] = $yxtoken;
        }
        return $this->json($data, 1000);
    }

    public function getCoachWyyx()
    {
        $get = input('get.');
        if (empty($get['coachid'])) {
            return $this->json([], 2000, '请求参数错误');
        }

        $info = $this->findTable('coach', ['where' => [
            ['isdel', '=', 0],
            ['coachid', '=', $get['coachid']]
        ]]);

        if (empty($info)) {
            return $this->json([], 2000, '教练不存在');
        }

        if (empty($info['yxaccid']) || empty($info['yxtoken'])) {
            $yx = new \app\common\lib\YxUtils();
            $res = $yx->createUserId('coach_' . $get['coachid'], $info['coachtruename']);
            if ($res['code'] == 200) {
                $yxaccid = empty($res['info']['accid']) ? '' : $res['info']['accid'];
                $yxtoken = empty($res['info']['token']) ? '' : $res['info']['token'];
            } else {
                $res = $yx->updateUserToken('coach_' . $get['coachid']);
                if ($res['code'] == 200) {
                    $yxaccid = empty($res['info']['accid']) ? '' : $res['info']['accid'];
                    $yxtoken = empty($res['info']['token']) ? '' : $res['info']['token'];
                } else {
                    return $this->json([], 2000, empty($res['desc']) ? json_encode($res) : $res['desc']);
                }
            }

            $where = ['coachid' => $info['coachid']];
            $update = [
                'where' => $where,
                'data' => [
                    'yxaccid' => $yxaccid,
                    'yxtoken' => $yxtoken
                ],
            ];
            $this->updateTable('coach', $update);
        } else {
            $yxaccid = $info['yxaccid'];
            $yxtoken = $info['yxtoken'];
        }

        $data = ['yxaccid' => $yxaccid];
        if ($this->userid == $get['coachid'] && $this->table == 'coach') {
            $data['yxtoken'] = $yxtoken;
        }
        return $this->json($data, 1000);
    }

    public function getYxUserInfo()
    {
        $get = input('get.');
        if (empty($get['yxaccid'])) {
            return $this->json([], 2000, '请求参数错误');
        }

        if (empty($get['table'])) {
            return $this->json([], 2000, '请求参数错误');
        }

        $info = $this->findTable($get['table'], ['where' => [
            ['isdel', '=', 0],
            ['yxaccid', '=', $get['yxaccid']]
        ]]);

        if (empty($info)) {
            return $this->json([], 2000, '信息为空');
        }

        if ($get['table'] == 'member') {
            unset($info['memberpassword']);
        } else {
            unset($get['coachpassword']);
        }

        return $this->json($info, 1000);
    }
}
